home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: array[index]
- Date: 1 Apr 1996 06:47:11 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4joq9fINNed0@keats.ugrad.cs.ubc.ca>
- References: <4jiies$3bh@fnord.dfw.net>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4jiies$3bh@fnord.dfw.net>,
- Azazel Diabolus (aka Fetelgeuse) <ftlgeuse@dfw.dfw.net> wrote:
- >On my platform's assembly language a[n] is the same as n[a]; is this also
- >valid in C? Does array[index] give the same address as index[array]? I
- >will try this after I post it but I would like to know if this is
- >something defined by the ANSI standard. Thanks,
-
- Funny you should ask, but it is so defined. I've never thought of it as a
- similarity to assembly language, but come to think of it, it does somewhat
- reinforce the common stereotype of C as a ``portable assembler''. Heh.
-
- The reason it works is because the expression E1[E2] is equivalent to
- *((E1) + (E2)) by definition. The latter is commutative, so it doesn't matter
- whether E1 is the pointer expression and E2 the integral expression or vice
- versa. Thus it follows that E1[E2] also commutes.
- --
-
-